package com.suixun.aspect;

import org.aspectj.lang.JoinPoint;

import com.suixun.enums.DataSourceType;
import com.suixun.util.DataSourceContextHolder;
/**
 * 
 * <p>Title: DataSourceAspect</p>
 * <p> 功能描述:aop切面，用于切换数据源 </p> 
 * @author	陈显强
 * @date	2017年3月6日上午9:24:30
 * @version 1.0
 */
public class DataSourceAspect{
	public void before(JoinPoint joinPoint){
		if(joinPoint.getSignature().getName().contains("Monitor")){
			DataSourceContextHolder.setDBType(DataSourceType.datasource2);
		}else if(joinPoint.getSignature().getName().contains("yxt")){
			DataSourceContextHolder.setDBType(DataSourceType.datasource3);
		}else {
			DataSourceContextHolder.setDBType(DataSourceType.datasource1);
		}
    }
	public void after(JoinPoint point) {
		if(DataSourceContextHolder.getDBType()==DataSourceType.datasource2){
			DataSourceContextHolder.clearDBType();
		}
		if(DataSourceContextHolder.getDBType()==DataSourceType.datasource3){
			DataSourceContextHolder.clearDBType();
		}
	}
}
